from flask import Flask, jsonify
from flask_sqlalchemy import SQLAlchemy
import sqlalchemy
import pandas as pd
app = Flask(__name__)
#用户名、密码、主机名、端口和数据库名
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://root:123@127.0.0.1:3306/baicaoshi"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
#创建数据库对象
db = SQLAlchemy(app)
@app.route('/')
def db_test():
    dict_show = {}  # 定义字典用于数据展示
    yao={}
    # 反射数据库中已存在的表，并获取所有存在的表对象。
    db.reflect()
    # 获取所有表名
   # 获取所有表名
    all_table = {table_obj.name: table_obj for table_obj in db.get_tables_for_bind()}
    # 获取demo表的所有数据
    all_data = db.session.query(all_table['caoyao'])
    for data in all_data:
        key=data[0]
        name=data[1]
        if key=='jingjie':
            yao[key]=[name]
            print(key)
            print(name)
            return jsonify(yao)
        else:
            pass
    

if __name__=="__main__":
    app.run(debug=True)